// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

// unit normal vector of the plane (MUST BE NORMALIZED)
//uniform vec3 vNormalVec;
//
//// normal-vector of plane: {a,b,c}
//// normal-vector = vNormalVec
//// d = (-ax - by - cz)
//// p = d / length(n)
//// length(n) = 1
//// p = d
//uniform float fP;
//
//// Max altitude (used to clamp altitude to 0->1)
uniform float fMaxAltitude;
uniform float fMinAltitudeWithRadius;

uniform vec3 vPlanetCentre;

uniform mat4 matWorldViewProjection;

// texture used to find UV
//uniform sampler2D sGroundPack;

// altitude of vertex
varying float fAlt;
// slope of vertex
varying float fSlope;

void main(void)
{
   vec3 normal = gl_Vertex.xyz - vPlanetCentre;

   fAlt = length(normal) - fMinAltitudeWithRadius;
   fAlt = fAlt / fMaxAltitude;

   normal = normalize(normal);
   
   // fSlope = acos(dot(gl_Normal, NormalVec) / length(gl_Normal) * length(NormalVec))
   fSlope = dot(gl_Normal, normal);
   fSlope = acos(fSlope);
   fSlope = fSlope / 3.14;

   gl_TexCoord[0] = gl_MultiTexCoord0;
   
   gl_Position = vec4( matWorldViewProjection * gl_Vertex );
   //gl_Position = ftransform();
}
